/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package logic;

import gui.Login;
import gui.MainWindow;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import util.Encrypt;
import util.PreferencesPPM;

/**
 *
 * Author: José Iván Palmer García
 * Author: Gema Lopez García
 * Esta clase nos implementará la lógica de el login.
 */
public class LoginLogic implements ActionListener {

    private MainWindow mw;
    private Login l;
    public static PreferencesPPM pref;
    private MainWindowLogic mwl;

    public LoginLogic(MainWindow mw, MainWindowLogic mwl) {
        this.mw = mw;
        this.mwl = mwl;
        pref = new PreferencesPPM();
        l = new Login(this);
        l.setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("Aceptar")) {
            if (pref.getUsuario().equals(Encrypt.encryptMD5(l.getUsuario())) &&
                    pref.getPasswd().equals(Encrypt.encryptMD5(l.getContrasena()))) {
                l.dispose();
                mw.ponerFullScreen();
                mwl.iconoTareas();
            }else{
                l.alertaVisible(true);
            }
        }
        else if(e.getActionCommand().equals("Resetear")){
            l.setContrasena("");
            l.setUsuario("");
        }
    }
}
